import Point from "./point.js";
import Random from "./random.js";

export default class NNode {
    constructor(opt = {}){
        this.centre = new Point(opt.x,opt.y);
        this.radius = opt.radius || 30;
        this.color = opt.color || Random.color();
        this.z = opt.z || 0;
        this.perv = opt.prev || null;
        this.next = opt.next || null;
        // 初始化结构
        this.element = document.createElement('div');
        this.element.classList.add(opt.nodeClass || 'body-node');
        this.element.style.position = 'absolute';
        this.element.style.left = this.centre.x - this.radius + 'px';
        this.element.style.top = this.centre.y - this.radius + 'px';
        this.element.style.background = this.color;
        this.element.style.zIndex = this.z;
    }
    render(parent){
        parent.appendChild(this.element);
    }
    move(){
        // this.centre.x = x;
        // this.centre.y = y;
        this.element.style.left = this.centre.x - this.radius + 'px';
        this.element.style.top = this.centre.y - this.radius + 'px';
    }
}